package com.hht.downloadmanager.handler;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;


import java.lang.ref.WeakReference;

public class DownLoadHandler extends Handler {
    private WeakReference<Activity> mActivityList;
    private DownLoadMessageCall downLoadMessageCall;

    public DownLoadHandler(Activity activity, DownLoadMessageCall downLoadMessageCall) {
        mActivityList = new WeakReference<>(activity);
        this.downLoadMessageCall = downLoadMessageCall;
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        Activity activity = mActivityList.get();
        if (activity == null || activity.isFinishing()) {
            removeCallbacksAndMessages(null);
            downLoadMessageCall = null;
            return;
        }
        if (downLoadMessageCall != null) {
            downLoadMessageCall.messageCallBack(msg,activity);
        }
    }
}

